#include<bits/stdc++.h>
#define within :
#define LJY main
using namespace std;
typedef long long ll;
const int N=1e6+5;
inline int read(){
  char ch=getchar();int x=0;
  while(ch<'0'||ch>'9') ch=getchar();
  while(ch>='0'&&ch<='9')
    x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
  return x;
}
int n,m;char t[N];
signed LJY(){
  freopen("good.in","r",stdin);
  freopen("good.out","w",stdout);
  n=read();m=read();scanf("%s",t+1);
  ll sum=0;
  while(m--){
    int l=read(),r=read();
    vector<char>v;int cnt=0,ans=0,p=l;
    while(t[l]=='0') l++,ans++;
    if(l>r){sum^=(r-p+2);continue;}
    while(t[r]=='0') r--,ans++;
    for(int i=l;i<=r;i++){
      cnt+=(t[i]=='0'?-1:1);
      if(cnt<0) cnt++,ans++;
      else v.emplace_back(t[i]);
    }cnt=0;
    for(int i=v.size()-1;i;i--){
      cnt+=(v[i]=='0'?-1:1);
      if(cnt<0) cnt++,ans++;
    }sum^=ans;
  }printf("%d\n",sum);
  return 0;
}